﻿<MudTable ServerData="ServerReload">
    <HeaderContent>
        <MudTh><MudTableSortLabel SortLabel="No." InitialDirection="SortDirection.Descending" T="int">Nr</MudTableSortLabel></MudTh>
    </HeaderContent>
    <RowTemplate>
        <MudTd DataLabel="Nr">@context</MudTd>
    </RowTemplate>
    <PagerContent>
        <MudTablePager />
    </PagerContent>
</MudTable>

@code {
    public static string __description__ = "The server-side loaded table should reflect initial sort direction in its initial table state.";

    private int _totalItems;

    /// <summary>
    /// Here we simulate getting the paged, filtered and ordered data from the server
    /// </summary>
    private Task<TableData<int>> ServerReload(TableState state, CancellationToken token)
    {
        var p = state.Page * 3;
        IEnumerable<int> data = new List<int> { 1 + p, 2 + p, 3 + p };
        _totalItems = 99;
        var sortedData = state.SortDirection == SortDirection.Descending ? data.Reverse() : data;

        return Task.FromResult(new TableData<int> { TotalItems = _totalItems, Items = sortedData });
    }
}
